<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	template="../../Template/TemplateAdmin.xhtml"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:rich="http://richfaces.org/rich">


	<ui:define name="title">
		Trang Quản lý Sản phẩm
  	</ui:define>


	<ui:define name="content">
		<!-- Content -->
		<div id="MainPanel" align="left">

			<div class="ContentPart">
				<h1 class="ContentPartTitle" align="center">TRANG QUẢN LÝ SẢN PHẨM</h1>
			</div>
			<div class="ContentPart">
				<h3 class="ContentPartHeader">Thao tác</h3>
				<div class="ContentPartContent">
					<div id="rightAction" align="right">
					<h:commandLink immediate="true"
							action="#{themSanPhamBean.ChuyenQuaTrangThemSanPham()}">
							<div class="actionLargeButton" align="center">
								<img class="buttonImage imgNoBackgroundBorder"
									src="../../Images/Icon/icon_addLarge.png" alt="Thêm" />
								<div class="buttonCaption">Thêm</div>
							</div>
						</h:commandLink>
						<h:commandLink immediate="true"
							action="#{quanLySanPhamBean.LietKeToanBo()}">
							<div class="actionWideButtonRight" align="center">
								<img class="buttonImage imgNoBackgroundBorder"
									src="../../Images/Icon/icon_lietKeLarge.png" alt="Liệt kê" />
								<div class="buttonCaption">Liệt kê toàn bộ</div>
							</div>
							<f:ajax render="tableContent" />
						</h:commandLink>
					</div>
					<div id="leftAction">
						<div class="ins">Tìm kiếm sản phẩm</div>
						<div id="Search">
							<h:inputText id="inputTim" class="txtField" type="text"
								value="#{quanLySanPhamBean.chuoiTimKiem}" />							
							<h:commandLink action="#{quanLySanPhamBean.TimKiem()}"
								outcom="TrangQuanLyLoaiSanPham">
								<div id="btSearch">Tìm</div>
							</h:commandLink>
						</div>
						<hr />
						<div class="ins">Liệt kê sản phẩm:</div>
						<div class="Filter">
							<!-- &nbsp;&nbsp;  -->
							<label for="cbbLoaiSanPham">Loại Sản phẩm: </label>

							<h:selectOneMenu name="cbbLoaiSanPham" id="cbbLoaiSanPham"
								class="combobox" value="#{quanLySanPhamBean.maLoaiLietKe}">
								<f:selectItem itemValue="-1" itemLabel="Tất cả" />
								<f:selectItems value="#{headerBean.lstLoaiSanPham}" var="danhMucLoaiSanPham"
									itemLabel="#{danhMucLoaiSanPham.getTenloaisanpham()}"
									itemValue="#{danhMucLoaiSanPham.getMaloaisanpham()}" />
							</h:selectOneMenu>
							<h:commandLink action="#{quanLySanPhamBean.LietKeTheoLoai()}"
								outcom="TrangQuanLySanPham">
								<div id="btFilter">Liệt kê</div>
							</h:commandLink>
						</div>
					</div>
				</div>
			</div>
			
			<div class="ContentPart">
				<div class="ContentPartContent">
					<h:messages id="messageNotification" />
				</div>
			</div>
			
			<!-- Content -->
			<div class="ContentPart">
				<h3 class="ContentPartHeader">Danh sách sản phẩm</h3>
				<h:panelGroup id="tableContent">
					<h:dataTable value="#{quanLySanPhamBean.lstSanPham}" var="sp"
						styleClass="tableDulieu"
						rendered="#{not empty quanLySanPhamBean.lstSanPham}"
						rowClasses="rowLe,rowChan">

						<ui:param name="index"
							value="#{quanLySanPhamBean.lstSanPham.indexOf(sp)}" />

						<h:column>
							<f:facet name="header">STT</f:facet>
							<h:outputText value="#{index + 1}" />
						</h:column>
						<h:column>
							<f:facet name="header">Mã SP</f:facet>
							<h:commandLink action="#{trangChiTietSanPhamBean.ShowSanPham(sp)}">#{sp.masanpham}</h:commandLink>
						</h:column>
						<h:column>
							<f:facet name="header">Tên SP</f:facet>
							<h:commandLink action="#{trangChiTietSanPhamBean.ShowSanPham(sp)}">#{sp.tensanpham}</h:commandLink>
						</h:column>
						<h:column>
							<f:facet name="header">Loại SP</f:facet>
							<h:outputText value="#{sp.loaisanpham.tenloaisanpham}" />
						</h:column>
						<h:column>
							<f:facet name="header">Nhà SX</f:facet>
							<h:outputText value="#{sp.nhasanxuat.tennhansanxuat}" />
						</h:column>
						<h:column>
							<f:facet name="header">Xuất xứ</f:facet>
							<h:outputText value="#{sp.xuatxu}" />
						</h:column>
						<h:column>
							<f:facet name="header">Ngày Nhận</f:facet>
							<h:outputText value="#{sp.ngaynhansanpham}" />
						</h:column>
						<h:column>
							<f:facet name="header">Số lượng bán / còn</f:facet>
							<h:outputText value="#{sp.soluongban} / #{sp.soluongtrongkho}" />
						</h:column>
						<h:column>
							<f:facet name="header">Giá</f:facet>
							<h:outputText value="#{sp.giaban}" styleClass="tien-te">
								<f:convertNumber groupingUsed="true" pattern="#0,000" />
							</h:outputText>
						</h:column>
						<h:column>
							<f:facet name="header">Xóa</f:facet>
							<h:outputText value="Xóa" rendered="#{sp.daxoa}" />							
							<h:outputText value="Chưa" rendered="#{not sp.daxoa}" />
						</h:column>
						<h:column>
							<f:facet name="header">Thao tác</f:facet>
							<div class="thaoTacCol">								
								<h:commandButton
									class="deleteIcon no-border pointerCursor flowToLeft"
									process="@this" immediate="true"
									onclick="if (confirm ('Bạn có chắc chắc muốn xóa Sản phẩm này?')) return true; return false;"
									action="#{quanLySanPhamBean.Xoa(sp)}"
									outcome="TrangQuanLySanPham"
									alt="Xóa" 
									rendered="#{not sp.daxoa}"/>
								<h:commandButton
									class="editIcon no-border pointerCursor flowToLeft"
									process="@this" immediate="true"
									action="#{themSanPhamBean.ChuyenQuaTrangSuaSanPham(sp)}"
									alt="Sửa" />
								<h:commandButton
									class="acceptIcon no-border pointerCursor flowToLeft"
									process="@this" immediate="true"
									onclick="if (confirm ('Bạn có chắc chắc muốn Hủy xóa Sản phẩm này?')) return true; return false;"
									action="#{quanLySanPhamBean.HuyXoa(sp)}"
									outcome="TrangQuanLySanPham"
									alt="Hủy Xóa" 
									rendered="#{sp.daxoa}"/>
							</div>
						</h:column>
					</h:dataTable>
				</h:panelGroup>
			</div>

		</div>
		<!-- Content -->
	</ui:define>
</ui:composition>